
#ifndef __I_FILERECORDMANGER_H__
#define __I_FILERECORDMANGER_H__

#include "RtBase.h"

/// macro used
/*if exception, backup file name: filename+YYYYMMDD+rand()+.bak */
#define FR_BACKUP_SUFFIX	".bak"

/// interface
class IFileRecordManager
{
public:
	static IFileRecordManager* Create(const CRtString& aFileName);
	static void Destory(IFileRecordManager* pFileRecord);

public:
	virtual RtResult Write(LPBYTE lpData, DWORD aLen) = 0;
	virtual RtResult Read(LPBYTE& lpBuffer, DWORD& aLen) = 0;
	virtual RtResult Read(std::vector<CRtString>& aRecords, DWORD aRecordNum) = 0;
	virtual void Skip(DWORD aLen) = 0;
	virtual void Remove() = 0;
	virtual DWORD GetLastEventId() = 0;
	virtual DWORD GetLastConfirmedEventId() = 0;

protected:
	virtual ~IFileRecordManager() {}
};

/// error code
#define RT_FREC_ERROR_BASE					RT_ERROR_MODULE_BASE+3000
/* Returned when a read file end */
#define RT_FREC_ERROR_EOF					(RtResult)(RT_FREC_ERROR_BASE + 1)
/* Returned when file format error */
#define RT_FREC_ERROR_FORMAT				(RtResult)(RT_FREC_ERROR_BASE + 2)
/* Returned when file c io function fails */
#define RT_FREC_ERROR_DISKIO				(RtResult)(RT_FREC_ERROR_BASE + 3)
/* Returned when read partial record */
// RT_ERROR_PARTIAL_DATA	--	by defined in RtError.h
/* Returned when an unexpected error occurs */
// RT_ERROR_UNEXPECTED		--	by defined in RtError.h
/* Returned when a memory allocation fails */
// RT_ERROR_OUT_OF_MEMORY	--	by defined in RtError.h

#endif //__I_FILERECORDMANGER_H__

